﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
using System.ComponentModel;
using System.IO;

namespace BDSim
{
    /// <summary>
    /// 用户段基准站
    /// </summary>
    [TypeConverter(typeof(PropertySorter))]
    public class StaticUser : UserBaseModel
    {
        #region 字段
        private ECoordinateType_ECF _CoordinateType = ECoordinateType_ECF.CGCS2000_BLH;
        private PosXYZClass _UserPosXYZ = new PosXYZClass();
        private PosBLHClass _UserPosBLH = new PosBLHClass();

        NodePosVel UserPosXYZ_CGCS2000 = new NodePosVel(-2148744.3968999996, 4426641.2099, 4044655.8564000013,0,0,0);
        NodePosVel UserPosXYZ_WGS84 = new NodePosVel();
        BLH_PosVel UserPosBLH_CGCS2000 = new BLH_PosVel();
        BLH_PosVel UserPosBLH_WGS84 = new BLH_PosVel();

        #region 存储数据
        string directoryname;//轨迹数据文件夹名称，暂时存储过程数据
        string ObsDatadirectoryname;//观测数据文件夹名称
        string PVTDatadirectoryname;//定位数据文件夹名称
        //string TrackDataFilename;//轨迹数据文件的名称，暂时存储过程数据
        string[] ObsDataFilename;//接收机观测数据文件的名称，暂时存储过程数据
        string[] PVTDataFilename;//接收机定位数据文件的名称，暂时存储过程数据
        string[] ObsTroErrDataFilename;//接收机观测误差数据——对流层误差文件的名称，存储过程数据
        string[] ObsIonErrDataFilename;//接收机观测误差数据——对流层误差文件的名称，存储过程数据
        string[] ObsOffErrDataFilename;//接收机观测误差数据——对流层误差文件的名称，存储过程数据
        #endregion 存储数据
        #endregion 字段

        #region 属性
        [XmlAttribute, DescriptionAttribute("静态用户在地固坐标系中的表示类型"), CategoryAttribute("用户位置信息")]
        public ECoordinateType_ECF CoordinateType
        {
            get { return _CoordinateType; }
            set
            {
                switch (value)
                {
                    case ECoordinateType_ECF.CGCS2000_XYZ:
                        PropertyFieldControl.SetPropertyVisibility(this, "UserPosXYZ", true);
                        PropertyFieldControl.SetPropertyVisibility(this, "UserPosBLH", false);

                        switch (_CoordinateType)
                        {
                            case ECoordinateType_ECF.WGS84_XYZ:
                                UserPosXYZ_WGS84.epoch = GlobalStartTime;
                                UserPosXYZ_WGS84.x = UserPosXYZ.X;
                                UserPosXYZ_WGS84.y = UserPosXYZ.Y;
                                UserPosXYZ_WGS84.z = UserPosXYZ.Z;

                                TimeSpaceDll.WGS2CGCS(UserPosXYZ_WGS84, out UserPosXYZ_CGCS2000);
                                TimeSpaceDll.XYZ2BLH(UserPosXYZ_CGCS2000, ECFtype.type_CGCS2000, out UserPosBLH_CGCS2000);
                                break;
                            case ECoordinateType_ECF.WGS84_BLH:
                                UserPosBLH_WGS84.epoch = GlobalStartTime;
                                UserPosBLH_WGS84.B = UserPosBLH.B;
                                UserPosBLH_WGS84.L = UserPosBLH.L;
                                UserPosBLH_WGS84.H = UserPosBLH.H;
                                TimeSpaceDll.BLH2XYZ(UserPosBLH_WGS84, ECFtype.type_WGS, out UserPosXYZ_WGS84);

                                UserPosXYZ_WGS84.epoch = GlobalStartTime;
                                TimeSpaceDll.WGS2CGCS(UserPosXYZ_WGS84, out UserPosXYZ_CGCS2000);
                                TimeSpaceDll.XYZ2BLH(UserPosXYZ_CGCS2000, ECFtype.type_CGCS2000, out UserPosBLH_CGCS2000);
                                break;
                            case ECoordinateType_ECF.CGCS2000_XYZ:
                                UserPosXYZ_CGCS2000.epoch = GlobalStartTime;
                                UserPosXYZ_CGCS2000.x = UserPosXYZ.X;
                                UserPosXYZ_CGCS2000.y = UserPosXYZ.Y;
                                UserPosXYZ_CGCS2000.z = UserPosXYZ.Z;

                                TimeSpaceDll.XYZ2BLH(UserPosXYZ_CGCS2000, ECFtype.type_CGCS2000, out UserPosBLH_CGCS2000);

                                break;
                            case ECoordinateType_ECF.CGCS2000_BLH:
                                UserPosBLH_CGCS2000.epoch = GlobalStartTime;
                                UserPosBLH_CGCS2000.B = UserPosBLH.B;
                                UserPosBLH_CGCS2000.L = UserPosBLH.L;
                                UserPosBLH_CGCS2000.H = UserPosBLH.H;
                                TimeSpaceDll.BLH2XYZ(UserPosBLH_CGCS2000, ECFtype.type_CGCS2000, out UserPosXYZ_CGCS2000);
                                break;
                            default:
                                break;
                        }

                        UserPosXYZ.X = UserPosXYZ_CGCS2000.x;
                        UserPosXYZ.Y = UserPosXYZ_CGCS2000.y;
                        UserPosXYZ.Z = UserPosXYZ_CGCS2000.z;
                        break;
                    case ECoordinateType_ECF.WGS84_XYZ:
                        PropertyFieldControl.SetPropertyVisibility(this, "UserPosXYZ", true);
                        PropertyFieldControl.SetPropertyVisibility(this, "UserPosBLH", false);
                        switch (_CoordinateType)
                        {
                            case ECoordinateType_ECF.CGCS2000_BLH: //原坐标类型
                                UserPosBLH_CGCS2000.epoch = GlobalStartTime;
                                UserPosBLH_CGCS2000.B = UserPosBLH.B;
                                UserPosBLH_CGCS2000.L = UserPosBLH.L;
                                UserPosBLH_CGCS2000.H = UserPosBLH.H;
                                TimeSpaceDll.BLH2XYZ(UserPosBLH_CGCS2000, ECFtype.type_CGCS2000, out UserPosXYZ_CGCS2000);
                                TimeSpaceDll.CGCS2WGS(UserPosXYZ_CGCS2000, out UserPosXYZ_WGS84);
                                break;

                            case ECoordinateType_ECF.WGS84_BLH: //原坐标类型
                                UserPosBLH_WGS84.epoch = GlobalStartTime;
                                UserPosBLH_WGS84.B = UserPosBLH.B;
                                UserPosBLH_WGS84.L = UserPosBLH.L;
                                UserPosBLH_WGS84.H = UserPosBLH.H;
                                TimeSpaceDll.BLH2XYZ(UserPosBLH_WGS84, ECFtype.type_WGS, out UserPosXYZ_WGS84);
                                TimeSpaceDll.WGS2CGCS(UserPosXYZ_WGS84, out UserPosXYZ_CGCS2000);
                                break;

                            case ECoordinateType_ECF.WGS84_XYZ: //原坐标类型
                                UserPosXYZ_WGS84.epoch = GlobalStartTime;
                                UserPosXYZ_WGS84.x = UserPosXYZ.X;
                                UserPosXYZ_WGS84.y = UserPosXYZ.Y;
                                UserPosXYZ_WGS84.z = UserPosXYZ.Z;
                                break;

                            case ECoordinateType_ECF.CGCS2000_XYZ://原坐标类型
                                UserPosXYZ_CGCS2000.epoch = GlobalStartTime;
                                UserPosXYZ_CGCS2000.x = UserPosXYZ.X;
                                UserPosXYZ_CGCS2000.y = UserPosXYZ.Y;
                                UserPosXYZ_CGCS2000.z = UserPosXYZ.Z;
                                TimeSpaceDll.CGCS2WGS(UserPosXYZ_CGCS2000, out UserPosXYZ_WGS84);
                                break;
                        }
                        UserPosXYZ.X = UserPosXYZ_WGS84.x;
                        UserPosXYZ.Y = UserPosXYZ_WGS84.y;
                        UserPosXYZ.Z = UserPosXYZ_WGS84.z;
                        break;
                    case ECoordinateType_ECF.CGCS2000_BLH:
                        PropertyFieldControl.SetPropertyVisibility(this, "UserPosXYZ", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "UserPosBLH", true);
                        switch (_CoordinateType)
                        {
                            case ECoordinateType_ECF.CGCS2000_BLH: //原坐标类型
                                UserPosBLH_CGCS2000.epoch = GlobalStartTime;
                                UserPosBLH_CGCS2000.B = UserPosBLH.B;
                                UserPosBLH_CGCS2000.L = UserPosBLH.L;
                                UserPosBLH_CGCS2000.H = UserPosBLH.H;
                                TimeSpaceDll.BLH2XYZ(UserPosBLH_CGCS2000, ECFtype.type_CGCS2000, out UserPosXYZ_CGCS2000);
                                break;

                            case ECoordinateType_ECF.WGS84_BLH: //原坐标类型
                                UserPosBLH_WGS84.epoch = GlobalStartTime;
                                UserPosBLH_WGS84.B = UserPosBLH.B;
                                UserPosBLH_WGS84.L = UserPosBLH.L;
                                UserPosBLH_WGS84.H = UserPosBLH.H;
                                TimeSpaceDll.BLH2XYZ(UserPosBLH_WGS84, ECFtype.type_WGS, out UserPosXYZ_WGS84);
                                TimeSpaceDll.WGS2CGCS(UserPosXYZ_WGS84, out UserPosXYZ_CGCS2000);
                                TimeSpaceDll.XYZ2BLH(UserPosXYZ_CGCS2000, ECFtype.type_CGCS2000, out UserPosBLH_CGCS2000);
                                break;

                            case ECoordinateType_ECF.WGS84_XYZ: //原坐标类型
                                UserPosXYZ_WGS84.epoch = GlobalStartTime;
                                UserPosXYZ_WGS84.x = UserPosXYZ.X;
                                UserPosXYZ_WGS84.y = UserPosXYZ.Y;
                                UserPosXYZ_WGS84.z = UserPosXYZ.Z;
                                TimeSpaceDll.WGS2CGCS(UserPosXYZ_WGS84, out UserPosXYZ_CGCS2000);
                                TimeSpaceDll.XYZ2BLH(UserPosXYZ_CGCS2000, ECFtype.type_CGCS2000, out UserPosBLH_CGCS2000);
                                break;

                            case ECoordinateType_ECF.CGCS2000_XYZ://原坐标类型
                                UserPosXYZ_CGCS2000.epoch = GlobalStartTime;
                                UserPosXYZ_CGCS2000.x = UserPosXYZ.X;
                                UserPosXYZ_CGCS2000.y = UserPosXYZ.Y;
                                UserPosXYZ_CGCS2000.z = UserPosXYZ.Z;
                                TimeSpaceDll.XYZ2BLH(UserPosXYZ_CGCS2000, ECFtype.type_CGCS2000, out UserPosBLH_CGCS2000);
                                break;
                        }
                        UserPosBLH.B = UserPosBLH_CGCS2000.B;
                        UserPosBLH.L = UserPosBLH_CGCS2000.L;
                        UserPosBLH.H = UserPosBLH_CGCS2000.H;
                        break;
                    case ECoordinateType_ECF.WGS84_BLH:
                        PropertyFieldControl.SetPropertyVisibility(this, "UserPosXYZ", false);
                        PropertyFieldControl.SetPropertyVisibility(this, "UserPosBLH", true);
                        switch (_CoordinateType)
                        {
                            case ECoordinateType_ECF.CGCS2000_BLH: //原坐标类型
                                UserPosBLH_CGCS2000.epoch = GlobalStartTime;
                                UserPosBLH_CGCS2000.B = UserPosBLH.B;
                                UserPosBLH_CGCS2000.L = UserPosBLH.L;
                                UserPosBLH_CGCS2000.H = UserPosBLH.H;
                                TimeSpaceDll.BLH2XYZ(UserPosBLH_CGCS2000, ECFtype.type_CGCS2000, out UserPosXYZ_CGCS2000);
                                TimeSpaceDll.CGCS2WGS(UserPosXYZ_CGCS2000, out UserPosXYZ_WGS84);
                                TimeSpaceDll.XYZ2BLH(UserPosXYZ_WGS84, ECFtype.type_WGS, out UserPosBLH_WGS84);

                                break;

                            case ECoordinateType_ECF.WGS84_BLH: //原坐标类型
                                UserPosBLH_WGS84.epoch = GlobalStartTime;
                                UserPosBLH_WGS84.B = UserPosBLH.B;
                                UserPosBLH_WGS84.L = UserPosBLH.L;
                                UserPosBLH_WGS84.H = UserPosBLH.H;
                                TimeSpaceDll.BLH2XYZ(UserPosBLH_WGS84, ECFtype.type_WGS, out UserPosXYZ_WGS84);
                                TimeSpaceDll.WGS2CGCS(UserPosXYZ_WGS84, out UserPosXYZ_CGCS2000);
                                break;

                            case ECoordinateType_ECF.WGS84_XYZ: //原坐标类型
                                UserPosXYZ_WGS84.epoch = GlobalStartTime;
                                UserPosXYZ_WGS84.x = UserPosXYZ.X;
                                UserPosXYZ_WGS84.y = UserPosXYZ.Y;
                                UserPosXYZ_WGS84.z = UserPosXYZ.Z;
                                TimeSpaceDll.XYZ2BLH(UserPosXYZ_WGS84, ECFtype.type_WGS, out UserPosBLH_WGS84);
                                TimeSpaceDll.WGS2CGCS(UserPosXYZ_WGS84, out UserPosXYZ_CGCS2000);
                                break;

                            case ECoordinateType_ECF.CGCS2000_XYZ://原坐标类型
                                UserPosXYZ_CGCS2000.epoch = GlobalStartTime;
                                UserPosXYZ_CGCS2000.x = UserPosXYZ.X;
                                UserPosXYZ_CGCS2000.y = UserPosXYZ.Y;
                                UserPosXYZ_CGCS2000.z = UserPosXYZ.Z;
                                TimeSpaceDll.CGCS2WGS(UserPosXYZ_CGCS2000, out UserPosXYZ_WGS84);
                                TimeSpaceDll.XYZ2BLH(UserPosXYZ_WGS84, ECFtype.type_WGS, out UserPosBLH_WGS84);
                                break;
                        }
                        UserPosBLH.B = UserPosBLH_WGS84.B;
                        UserPosBLH.L = UserPosBLH_WGS84.L;
                        UserPosBLH.H = UserPosBLH_WGS84.H;
                        break;
                }

                _CoordinateType = value;
                //根据界面选中的卫星坐标类型选择显示不同的坐标属性设置
                BDSimObject.DisplayObjectProperty(this);
            }
        }

        [Browsable(false), DescriptionAttribute("静态用户在地固坐标系中的直角坐标"), CategoryAttribute("用户位置信息")]
        public PosXYZClass UserPosXYZ
        {
            get
            {
                return _UserPosXYZ;
            }
            set
            {
                _UserPosXYZ = value;
            }
        }

        [Browsable(true), DescriptionAttribute("静态用户在地固坐标系中的大地坐标"), CategoryAttribute("用户位置信息"), TypeConverter(typeof(PropertySorter))]
        public PosBLHClass UserPosBLH
        {
            get
            {
                return _UserPosBLH;
            }
            set
            {
                _UserPosBLH = value;
            }
        }

        #endregion 属性

        public StaticUser()
        {
            Name = "静态用户";
            Type = EUserType.StaticUser;
            DefineCommand();
            Menu.ItemsSource = MenuCommandList;
        }

        #region 初始化
        public override void Init()
        {
            base.Init();

            #region 位置信息初始化
            if (ECoordinateType_ECF.CGCS2000_BLH== CoordinateType)//用于该情况：用户直接在界面设置CGCS_2000 坐标
            {
                UserPosBLH_CGCS2000.epoch = GlobalStartTime;
                UserPosBLH_CGCS2000.B = UserPosBLH.B;
                UserPosBLH_CGCS2000.L = UserPosBLH.L;
                UserPosBLH_CGCS2000.H = UserPosBLH.H;
                TimeSpaceDll.BLH2XYZ(UserPosBLH_CGCS2000, ECFtype.type_CGCS2000, out UserPosXYZ_CGCS2000);
            }
            if (ECoordinateType_ECF.WGS84_XYZ == CoordinateType)//用于该情况：用户直接在界面设置WGS84_XYZ坐标
            {
                UserPosXYZ_WGS84.epoch = GlobalStartTime;
                UserPosXYZ_WGS84.x = UserPosXYZ.X;
                UserPosXYZ_WGS84.y = UserPosXYZ.Y;
                UserPosXYZ_WGS84.z = UserPosXYZ.Z;
                TimeSpaceDll.WGS2CGCS(UserPosXYZ_WGS84, out UserPosXYZ_CGCS2000);
            }
            if (ECoordinateType_ECF.WGS84_BLH == CoordinateType)//用于该情况：用户直接在界面设置WGS84_BLH 坐标
            {
                UserPosBLH_WGS84.epoch = GlobalStartTime;
                UserPosBLH_WGS84.B = UserPosBLH.B;
                UserPosBLH_WGS84.L = UserPosBLH.L;
                UserPosBLH_WGS84.H = UserPosBLH.H;

                TimeSpaceDll.BLH2XYZ(UserPosBLH_WGS84, ECFtype.type_WGS, out UserPosXYZ_WGS84);
                TimeSpaceDll.WGS2CGCS(UserPosXYZ_WGS84, out UserPosXYZ_CGCS2000);
            }
            if (ECoordinateType_ECF.CGCS2000_XYZ == CoordinateType)//用于该情况：用户直接在界面设置CGCS2000_XYZ 坐标
            {
                UserPosXYZ_CGCS2000.epoch = GlobalStartTime;
                UserPosXYZ_CGCS2000.x = UserPosXYZ.X;
                UserPosXYZ_CGCS2000.y = UserPosXYZ.Y;
                UserPosXYZ_CGCS2000.z = UserPosXYZ.Z;
            }

            NodePosVel xyz = new NodePosVel();
            xyz.x = UserPosXYZ_CGCS2000.x;//系统运行中统一使用CGCS2000坐标系
            xyz.y = UserPosXYZ_CGCS2000.Y;
            xyz.z = UserPosXYZ_CGCS2000.Z;
            PosVelXYZ = xyz;

            TimeSpaceDll.XYZ2BLH(UserPosXYZ_CGCS2000, ECFtype.type_CGCS2000, out UserPosBLH_CGCS2000);
            PosVelBLH = UserPosBLH_CGCS2000;//系统运行中统一使用CGCS2000坐标系
            #endregion 位置信息初始化

            #region 气象参数初始化
            GetMeteorological(GlobalStartTime);
            #endregion 气象参数初始化

            #region 存储数据
            string defaultpath = Directory.GetCurrentDirectory() + "\\DataRecords\\用户段\\静态用户\\";
            DateTime NowTime = DateTime.Now;
            string NowTimeString = NowTime.Year.ToString() + string.Format("{0:D2}", NowTime.Month) + string.Format("{0:D2}", NowTime.Day) +
                "_" + string.Format("{0:D2}", NowTime.Hour) + "_" + string.Format("{0:D2}", NowTime.Minute) + "_" + string.Format("{0:D2}", NowTime.Second);

            directoryname = defaultpath + "自定义数据_" + NowTimeString + "\\" + Name + "\\";
            if (!Directory.Exists(directoryname))
            {
                Directory.CreateDirectory(directoryname);
            }

            //观测数据、定位数据文件名赋值
            ObsDataFilename = new string[RecCollection.Count()];
            PVTDataFilename = new string[RecCollection.Count()];
            ObsTroErrDataFilename=new string[RecCollection.Count()];
            ObsIonErrDataFilename=new string[RecCollection.Count()];
            ObsOffErrDataFilename=new string[RecCollection.Count()];

            ObsDatadirectoryname = directoryname + "观测数据\\";
            PVTDatadirectoryname = directoryname + "定位数据\\";
            if (!Directory.Exists(ObsDatadirectoryname))
            {
                Directory.CreateDirectory(ObsDatadirectoryname);
            }
            if (!Directory.Exists(PVTDatadirectoryname))
            {
                Directory.CreateDirectory(PVTDatadirectoryname);
            }
            for (int i = 0; i < RecCollection.Count(); i++)
            {
                ObsDataFilename[i] = ObsDatadirectoryname + "BDSim_" + Name + "_" + string.Format("{0}号接收机观测数据.txt", RecCollection[i].Id);
                PVTDataFilename[i] = PVTDatadirectoryname + "BDSim_" + Name + "_" + string.Format("{0}号接收机定位数据.txt", RecCollection[i].Id);
                if (Scenario._IsTestingMode)//通过场景开关判断是否存数据
                {
                    ObsTroErrDataFilename[i] = ObsDatadirectoryname + "BDSim_" + Name + "_" + string.Format("{0}号接收机对流层误差数据.txt", RecCollection[i].Id);
                    ObsIonErrDataFilename[i] = ObsDatadirectoryname + "BDSim_" + Name + "_" + string.Format("{0}号接收机电离层误差数据.txt", RecCollection[i].Id);
                    ObsOffErrDataFilename[i] = ObsDatadirectoryname + "BDSim_" + Name + "_" + string.Format("{0}号接收机相位中心偏移误差数据.txt", RecCollection[i].Id);
                }
                
            }
            #endregion 存储数据

            foreach (var item in RecCollection)
            {
                item.Parent = this;
                item.Init();
            }

            //初始化完成反馈任务执行量
            DlgAddCompleteMission();
        }
        #endregion

        #region 单步运行
        public override void StepRun()
        {
            base.StepRun();

            #region 存储数据
            double nowTime = (BDSimObject.GlobalCurrentTime.Jd - BDSimObject.GlobalStartTime.Jd) * 86400.0;//当前系统运行时刻
            int timeID = (int)(nowTime);


            int id = -1;//接收机列表中的接收机序号
            //存储文件中的时间信息
            string data1 = BDSimObject.GlobalCurrentTime.Year.ToString() + " " + BDSimObject.GlobalCurrentTime.mon.ToString().PadLeft(2) + " " + BDSimObject.GlobalCurrentTime.Day.ToString().PadLeft(2) +
                                " " + BDSimObject.GlobalCurrentTime.hour.ToString().PadLeft(2) + " " + BDSimObject.GlobalCurrentTime.min.ToString().PadLeft(2) + " " + BDSimObject.GlobalCurrentTime.sec.ToString("00:000") + " ";

            //数据文件中时间暂定为GPS时间
            //UTCTime GPST = new UTCTime();
            //double GPS_JD;
            //TimeSpaceDll.UTC2GPST(BDSimObject.GlobalCurrentTime.Jd,out GPS_JD);
            //GPST.Jd = GPS_JD;
            //TimeSpaceDll.CAL2UTC(out GPST, 2);
            //string data1 = GPST.Year.ToString() + " " + GPST.mon.ToString().PadLeft(2) + " " + GPST.Day.ToString().PadLeft(2) +
            //                    " " + GPST.hour.ToString().PadLeft(2) + " " + GPST.min.ToString().PadLeft(2) + " " + GPST.sec.ToString("00:000") + " ";

            string data;
            #endregion 存储数据

            NodePosVel xyz = new NodePosVel();
            xyz.x = UserPosXYZ_CGCS2000.x;//系统运行中统一使用CGCS2000坐标系
            xyz.y = UserPosXYZ_CGCS2000.Y;
            xyz.z = UserPosXYZ_CGCS2000.Z;
            PosVelXYZ = xyz;

            TimeSpaceDll.XYZ2BLH(UserPosXYZ_CGCS2000, ECFtype.type_CGCS2000, out UserPosBLH_CGCS2000);
            PosVelBLH = UserPosBLH_CGCS2000;//系统运行中统一使用CGCS2000坐标系

            #region 气象参数初始化
            GetMeteorological(BDSimObject.GlobalCurrentTime);
            #endregion 气象参数初始化
            foreach (var item in RecCollection)
            {
                item.StepRun();
                FixedPosVelXYZ = item.FixedPosVelXYZ;

                #region 存储数据
                id++;

                for (int i = 0; i < item.ObsSatsDataList.Count(); i++)
                {
                    //存储观测数据
                    data = data1 + item.ObsSatsDataList[i][0].SatID.ToString().PadLeft(2, ' ') + " ";//zly2022
                    for (int j = 0; j < item.ObsSatsDataList[i].Count(); j++)
                    {
                        data += item.ObsSatsDataList[i][j].SatObs.A_Pseudo_writein.ToString() + " ";
                        data += item.ObsSatsDataList[i][j].SatObs.A_Carri_writein.ToString() + " ";
                    }
                    data += "\n";


                    File.AppendAllText(ObsDataFilename[id], data);

                    if (Scenario._IsTestingMode)//通过场景开关判断是否存数据
                    {
                        //存储对流层误差数据
                        data = data1;
                        data += item.RecObsDataGen.RecObsErrOutputList[i].SatID.ToString().PadLeft(2, ' ') + " ";
                        data += item.RecObsDataGen.RecObsErrOutputList[i].DeltTro.ToString() + "\n";
                        File.AppendAllText(ObsTroErrDataFilename[id], data);

                        //存储电离层误差数据
                        data = data1;
                        data += item.RecObsDataGen.RecObsErrOutputList[i].SatID.ToString().PadLeft(2, ' ') + " ";
                        data += item.RecObsDataGen.RecObsErrOutputList[i].DeltIon[0].ToString() + " ";
                        data += item.RecObsDataGen.RecObsErrOutputList[i].DeltIon[1].ToString() + "\n";
                        File.AppendAllText(ObsIonErrDataFilename[id], data);

                        //存储相位中心偏移误差数据
                        data = data1;
                        data += item.RecObsDataGen.RecObsErrOutputList[i].SatID.ToString().PadLeft(2, ' ') + " ";
                        data += item.RecObsDataGen.RecObsErrOutputList[i].DeltOff.ToString() + "\n";
                        File.AppendAllText(ObsOffErrDataFilename[id], data);
                    }

                }

                //存储定位数据
                data = data1;
                data += FixedPosVelXYZ.x.ToString() + " ";
                data += FixedPosVelXYZ.y.ToString() + " ";
                data += FixedPosVelXYZ.z.ToString() + " ";
                data += (FixedPosVelXYZ.x - PosVelXYZ.x).ToString() + " ";
                data += (FixedPosVelXYZ.y - PosVelXYZ.y).ToString() + " ";
                data += (FixedPosVelXYZ.z - PosVelXYZ.z).ToString() + "\n";
                File.AppendAllText(PVTDataFilename[id], data);

                #endregion 存储数据
            }
        }
        #endregion

        #region 右键命令
        #region 右键命令定义
        [XmlIgnore]
        public List<MenuCommand> MenuCommandList = new List<MenuCommand>();

        MenuCommand AddRecCmd = new MenuCommand();
        MenuCommand DeleteRecCmd = new MenuCommand();
        #endregion 右键命令定义

        //命令集合初始化
        public void DefineCommand()
        {
            AddRecCmd.Header = "新建接收机";
            AddRecCmd.DefineExcuteCommand(AddRecCmdFun_Execute, AddRecCmdFun_CanExecute);

            MenuCommandList.Add(AddRecCmd);

            DeleteRecCmd.Header = "删除";
            DeleteRecCmd.DefineExcuteCommand(DeleteRecCmdFun_Execute, DeleteRecCmdFun_CanExecute);

            MenuCommandList.Add(DeleteRecCmd);

        }

        //接收机添加命令实现
        void AddRecCmdFun_Execute(object param)
        {
            CReceiver Rec = new CReceiver();
            Rec.Name = String.Format("Receiver{0}", RecCollection.Count() + 1);
            Rec.Id = RecCollection.Count() + 1;
            Rec.Parent = this;

            RecCollection.Add(Rec);
        }
        bool AddRecCmdFun_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
            }
            return flag;
        }

        //接收机删除命令实现
        void DeleteRecCmdFun_Execute(object param)
        {
            //删除载体
            StaticUser staticuser;
            for (int i = 0; i < Parent.UserModelList.Count(); i++)
            {
                if (Uid == Parent.UserModelList[i].Uid)
                {
                    staticuser = (StaticUser)Parent.UserModelList[i];
                    Parent.UserModelList.Remove(staticuser);
                }
            }

            //删除载体上的接收机
            RecCollection.Clear();
        }
        bool DeleteRecCmdFun_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
            }
            return flag;
        }
        #endregion 右键命令
    }
}
